<?php
if(isset($_GET['at'])) { 
//LEVEL CHNG
if ($_GET['at'] == 'CL' || $_GET['at'] == 'DL') {
	if($_GET['at'] == 'CL') { $_GET['ID'] = 0; }
	# DO PRC
		CONN('MYI');
		$GLOBALS['MYI']->multi_query("CALL fn_clearrates({$_GET['ID']},@htrID); SELECT @htrID;");
		 do {
			if ($result = $GLOBALS['MYI']->store_result()) {
				while ($row = $result->fetch_row()) {
				}
				$result->free();
			}
		} while ($GLOBALS['MYI']->next_result());
		$GLOBALS['MYI']->close();
	## END PRC
}
if ($_GET['at'] == 'AP') {
	//=========== Populate Rate ====================
	
	$htrCorresponsal = $_POST['htr_Corresponsal'];
	$htrMCobro = $_POST['htr_MCobro'];
	$htrMPago = $_POST['htr_MPago'];
	$htrDivisa = $_POST['htr_Divisa'];
	$htrCambio = $_POST['htr_Cambio'];
	$htrTasa = $_POST['htr_Tasa'];
	$htrNacLocal = $_POST['htr_NacLocal'];
	$htrPoints = $_POST['htr_Points'];
	$htrDateTime = $_POST['Date_Prod'].' '.$_POST['Time_Prod'].':00';

	# GET TARS
	$gTars = $_POST['htr_Tarifa'];
	$cgTars = count($gTars);
	
	# GET DST COUNTRIES
	$gDstCountry = $_POST['htr_Pais'];
	$cgDstCountry = count($gDstCountry);
	for($t=0;$t<$cgTars;$t++) {
		for($d=0;$d<$cgDstCountry;$d++) {
		# DO PRC
		CONN('MYI');
		$GLOBALS['MYI']->multi_query("CALL fn_setrates(@htrID,{$htrCorresponsal},{$htrMCobro},'{$htrMPago}',{$gTars[$t]},{$gDstCountry[$d]},{$htrDivisa},{$htrCambio},
										{$htrTasa},{$htrNacLocal},{$htrPoints},{$_SESSION[$SESSID]},'{$htrDateTime}','{$sysTime}'); SELECT @htrID;");
		 do {
			if ($result = $GLOBALS['MYI']->store_result()) {
				while ($row = $result->fetch_row()) {
				}
				$result->free();
			}
		} while ($GLOBALS['MYI']->next_result());
		$GLOBALS['MYI']->close();
		## END PRC
		}
	}
	

		
		}
}